package test.yzx.pproject.testView;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.ImageView;

public class ZiView extends ImageView {
    public ZiView(Context context) {
        super(context);
    }

    public ZiView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ZiView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    public void start(final int duration){
        post(new Runnable() {
            public void run() {
                ValueAnimator anim = ValueAnimator.ofInt(0, getWidth()).setDuration(duration);
                anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    public void onAnimationUpdate(ValueAnimator animation) {
                        currentRight = (int) animation.getAnimatedValue();
                        invalidate();
                    }
                });
                anim.start();
            }
        });
    }


    private int currentRight;

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.clipRect(0, 0, currentRight, getHeight());
        super.onDraw(canvas);
    }

}
